<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8" />
    <title>Editor.md</title>
    <link rel="stylesheet" href="../../static/css/style.css" />
    <link rel="stylesheet" href="../../static/css/editormd.css" />
    <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
</head>
<body>
    <div id="layout">
        <header>
            <h1>markdown编辑器</h1>
        </header>
        <form name="mdEditForm">
            <div id="test-editormd">
                <!--该区域内容为文字内容，非html内容-->
                <textarea style="display:none;" name="content" id="content">

                </textarea>
            </div>
        </form>
    </div>
    <script src="../../static/js/jquery.min.js"></script>
    <script src="../../static/js/editormd.min.js"></script>
    <script type="text/javascript">
        var testEditor;

        $(function() {
            testEditor = editormd("test-editormd", {
                width   : "90%",
                height  : 640,
                syncScrolling : "single",
                path    : "../../static/lib/",

                /**下述为新增，上面一行记得加逗号结束*/
                /*指定需要显示的功能按钮*/
                toolbarIcons : function() {
                    return ["undo", "redo", "|","bold", "italic","ucwords","uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","table","datetime","hr",  "||",  "watch", "fullscreen", "preview", "releaseIcon", "index"]
                },

                /*自定义功能按钮，下面我自定义了2个，一个是发布，一个是返回首页*/
                toolbarIconTexts : {
                    releaseIcon : "<span bgcolor=\"gray\">发布</span>",
                    index : "<span bgcolor=\"red\">返回首页</span>",
                },

                /*给自定义按钮指定回调函数*/
                toolbarHandlers:{
                    releaseIcon : function(cm, icon, cursor, selection) {
                        //提交表单代码在下面
                        contentCommit();
                        console.log("日志输出 testIcon =>", this, cm, icon, cursor, selection);
                    },
                    index : function(){
                        window.location.href = '/admin/index';
                    }
                }
            });
            /*提交表单的js*/
            function contentCommit(){
                mdEditForm.method = "post";
                //提交至服务器的路径
                mdEditForm.action = "/admin/contentCommit";
                mdEditForm.submit();
            }
        });
    </script>
</body>
</html>